<?php

namespace App\Http\Requests\System;

use Illuminate\Foundation\Http\FormRequest;

class SysAccessRequest extends FormRequest
{
    /**
     * 表示验证器是否应在第一个规则失败时停止
     *
     * @var bool
     */
    protected $stopOnFirstFailure = true;

    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
     */
    public function rules(): array
    {
        return [
            'title' => 'required|max:64',
            'permission' => 'required|max:128',
            'access_type' => 'required|integer',
            'parent_id' => 'required|integer',
            'sort' => 'required|integer',
        ];
    }

    /**
     * 获取验证错误的自定义属性
     *
     * @return string[]
     */
    public function attributes()
    {
        return [
            'title' => '权限名称',
            'permission' => '权限标识',
            'access_type' => '权限类型',
            'parent_id' => '父级权限',
            'sort' => '排序字段',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息
     *
     * @return string[]
     */
    public function messages()
    {
        return [
            'title.required' => '权限名称不能为空',
            'permission.required' => '权限标识不能为空',
            'access_type.required' => '权限类型不能为空',
            'parent_id.required' => '父级权限不能为空',
            'sort.required' => '排序字段不能为空',
        ];
    }
}
